module.exports = function ($scope, $modalInstance, $resource, $modal, item,change_type, flag, toaster){
    

    //查询type列表
    $scope.search = function (){
        var para = {
            'type': '4',
            'state': '1'
        }
        $resource('/api/as/goc/pelawinfo/findTypeList', {}, {}).save(para, function(res){
            if(res.errcode === 0){
                $scope.typelist = res.data.results;
            }else{
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }


    init();
    function init(){
        $scope.rulesinfo = flag ? {'flag': true} : angular.copy(item);
        if(change_type == '0'){
            $scope.rulesinfo.url = '/api/ac/goc/counselingService/save';
        }else if(change_type == '1'){
            $scope.rulesinfo.url = '/api/ac/goc/counselingService/saveChangeOldLog';
        }else if(change_type == '2'){
            $scope.rulesinfo.url = '/api/ac/goc/counselingService/saveNote';
        }else if(flag){
            $scope.rulesinfo.url = '/api/ac/goc/counselingService/save';
        }
        console.log($scope.rulesinfo.url)
        $scope.search();
    }
    //保存
    $scope.save = function (){
        if($scope.rulesinfo.type == undefined){
            toaster.error({title: '', body: '请选择类别！'});
          return;
        }
        if($scope.rulesinfo.info == undefined){
            toaster.error({title: '', body: '请输入详情！'});
          return;
        }
        if($scope.rulesinfo.title == undefined){
            toaster.error({title: '', body: '请输入标题！'});
          return;
        }
        var para = {
            'title': $scope.rulesinfo.title,
            'info': $scope.rulesinfo.info,
            'type': $scope.rulesinfo.type,
            'id' :  $scope.rulesinfo.id
        }
        $resource($scope.rulesinfo.url, {}, {}).save(para, function(res){
            if(res.errcode === 0){
                toaster.success({title: '', body: '保存成功'});
                $modalInstance.close();
            }else{
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }
   
    //取消
    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    }


     //同意
     $scope.agreelog = function (){
        
        var para = {
             
            'id' :  $scope.rulesinfo.id
        }
        $resource('/api/ac/goc/counselingService/updateagree', {}, {}).save(para, function(res){
            if(res.errcode === 0){
                toaster.success({title: '', body: '成功'});
                $modalInstance.close();
            }else{
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }


     //拒绝
     $scope.disagreelog = function (){
     
        var para = {
            
            'id' :  $scope.rulesinfo.id
        }
        $resource('/api/ac/goc/counselingService/updatedisagree', {}, {}).save(para, function(res){
            if(res.errcode === 0){
                toaster.success({title: '', body: '成功'});
                $modalInstance.close();
            }else{
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }
};